# 70. 灰度图存储
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', function(line) {
if(!this.compressedData) {
this.compressedData = line.split(' ').map(Number);
this.rows = this.compressedData[0];
this.cols = this.compressedData[1];
} else {
const x = line.split(' ').map(Number);
const targetRow = x[0];
const targetCol = x[1];
const ix = [];
for(let i=0; i<this.rows; i++) {
ix[i] = new Array(this.cols).fill(0);
}
let index = 2;
let currentRow = 0;
let currentCol = 0;
while(index < this.compressedData.length) {
const value = this.compressedData[index++];
const count = this.compressedData[index++];
for(let i=0; i<count; i++) {
ix[currentRow][currentCol++] = value;
if (currentCol === this.cols) {
currentRow++;
currentCol = 0;
}
}
}
console.log(ix[targetRow][targetCol]);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37